#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n = 0;
    scanf("%d", &n);
    int* num = (int*)malloc(sizeof(int) * n);
    for(int i = 0; i < n; i++)
    {
        int a = 0, b = 0, count = 0, j = 1, a_num = 1,b_num = 0, flag1 = 1, flag2 = 0;
        char* ret = NULL;
        char arr[100000] = {0};
        scanf("%d%d", &a, &b);
        getchar();
        while((arr[0] = getchar()) == '0');
        while((arr[j++] = getchar()) != '\n')
        {
            flag1 = 0;
        }
        if(flag1)
        {
            num[i] = 0;
            continue;
        }
        for(int i = 1; i < j; i++)
        {
            if(arr[i] == '1'&&arr[i-1] == '0')//a数量加一，结算前方0
            {
                if(a <= b * count)
                a_num++;
                else
                b_num = count;
                count = 0;
            }
            else if(arr[i] == '1'&&arr[i-1] == '1')//连续一无意义
            {;}
            else if(arr[i] == '0'&&arr[i-1] == '1')//开始统计零
            {
                count++;
                flag2 = 1;
            }
            else if(arr[i] == '0'&&arr[i-1] == '0'&&flag2)//连续零统计
            {
                count++;
            }
        }
        if(a_num == 0)
        {
            num[i] = 0;
            continue;
        }
        num[i] = a_num * a + b_num * b;
    }
    for(int i = 0; i < n; i++)
    {
        printf("%d\n", num[i]);
    }
    free(num);
    return 0;
}